package com.duqc.web.service.impl;

import com.duqc.web.service.RetryableService;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;

import java.time.LocalTime;

/**
 * @ClassName RetryableServiceImpl
 * @Description RetryableServiceImpl
 * @Author duqc
 * @Date 2023/3/20
 **/
@Service
public class RetryableServiceImpl implements RetryableService {

    @Override
    @Retryable(value = Exception.class, maxAttempts = 5, backoff = @Backoff(delay = 2000, multiplier = 1.5))
    public String demo(int code) throws Exception {
        System.out.println("demo被调用，时间：" + LocalTime.now());
        if (code == 0) {
            throw new Exception("失败");
        }
        System.out.println("成功");
        return null;
    }

}
